﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HIWSystem.Common;
using HIWSystem.Models;

namespace HIWSystem.Views
{
    /// <summary>
    /// LogIn.xaml 的交互逻辑
    /// </summary>
    public partial class LogIn : Window
    {
        string user = string.Empty;
        string password = string.Empty;
        public LogIn()
        {

            InitializeComponent();
            ViewManager.Register("Main",typeof(MainWindow),this);
        }

        private void btn_Cancel_Click(object sender, RoutedEventArgs e)
        {
            Environment.Exit(0);//退出系统
        }
        private void btn_Login_Click(object sender, RoutedEventArgs e)
        {
            user = txtUser.Text.Trim().ToUpper();
            password = txtPassword.Password.Trim().ToUpper();
            if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password))
            {
                TipInfo.Text = "用户名或者密码为空";
                return;
            }
            string retResult = BusinessProcess.GetLogInResult(user, password);
            if (retResult.Split('|')[0].ToString() == "OK")
            {
                LogInInfo.User = user;
                LogInInfo.Password = password;
                ViewManager.Show("Main");
                this.Hide();
            }
            else //登录失败
            {
                TipInfo.Text = retResult.Split('|')[1].ToString();
               return;
            }
        }

        private void txtUser_TextChanged(object sender, TextChangedEventArgs e)
        {
            TipInfo.Text = "";
        }

        private void txtPassword_PasswordChanged(object sender, RoutedEventArgs e)
        {
            TipInfo.Text = "";
        }
    }
}
